<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
<!--        <a-row style='height: 75px'>-->
<!--          <a-col>-->
<!--            <a-form-model-item label='科目' prop='subjectId'>-->
<!--              <s-dict-select-tag v-model='serchParams.subjectId' placeholder='请选择科目'-->
<!--                                 dictCode='cou_subject,subject_name,id' />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--        </a-row>-->
        <a-row>
          <a-col style='float: left' :span='8'>
            <a-form-model-item label='学年' prop='schoolYearId'>
              <s-dict-select-tag style='overflow-y: scroll;height: 35px' v-model='serchParams.schoolYearId' placeholder='请选择学年'
                                 dictCode='cou_school_year,school_year_name,id' />
            </a-form-model-item>
          </a-col>
          <a-col :span='8'>
            <a-form-model-item label='学期' prop='semesterId'>
              <s-dict-select-tag v-model='serchParams.semesterId' placeholder='请选择学期'
                                 dictCode='cou_semester,semester_name,id' />
            </a-form-model-item>
          </a-col>
        </a-row>
        <div v-if='toggleSearchStatus'>
          <a-row>
            <a-col style='float: left' :span='8'>
              <a-form-model-item label='年级' prop='gradeId'>
                <s-dict-select-tag v-model='serchParams.gradeId' placeholder='请选择年级'
                                   dictCode='cou_grade,grade_name,id' />
              </a-form-model-item>
            </a-col>
            <a-col style='float: left' :span='8'>
              <a-form-model-item label='计划状态' prop='coursePlanStatus'>
                <s-dict-select-tag v-model='serchParams.coursePlanStatus' placeholder='请选择计划状态'
                                   dictCode='course_plan_status' />
              </a-form-model-item>
            </a-col>
            <a-col :span='8'>
              <a-form-model-item label='启用状态' prop='izOpen'>
                <s-dict-select-tag v-model='serchParams.izOpen'
                                   dictCode='iz_open' placeholder='选择是否启用状态' />
              </a-form-model-item>
            </a-col>
          </a-row>
        </div>
        <a-row>
          <a-col :offset='8'>
            <span style='overflow: hidden;margin-top: 5px' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='whereSerchCoursePlan' icon='search'>查询</a-button>
              <a-button type='primary' @click='whereSerchCoursePlanInit' icon='reload'
                        style='margin-left: 8px'>重置</a-button>
               <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <a-button @click='handleAdd' type='primary' icon='plus'>新增</a-button>
      <a-button type='primary' icon='download' @click="handleExportXls('cou_course_plan')">导出</a-button>
      <a-upload name='file' :showUploadList='false' :multiple='false' :headers='tokenHeader' :action='importExcelUrl'
                @change='handleImportExcel'>
        <a-button type='primary' icon='import'>导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList='superFieldList' ref='superQueryModal'
                     @handleSuperQuery='handleSuperQuery'></j-super-query>
      <a-dropdown v-if='selectedRowKeys.length > 0'>
        <a-menu slot='overlay'>
          <a-menu-item key='1' @click='batchDel'>
            <a-icon type='delete' />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style='margin-left: 8px'> 批量操作
          <a-icon type='down' />
        </a-button>
      </a-dropdown>
      <a-button type='primary' icon='deployment-unit' @click='coursePlanApp'>开始下达教学计划</a-button>
      <a-button type='primary' icon='deployment-unit' @click='viewCoursePlanAppDetails'>查看计划下达记录</a-button>
      <template>
        <span style="float:right;">
          <a @click="searchQuery()"><a-icon type="sync" />刷新</a>
          <a-divider type="vertical" />
          <a-button v-print="'#datatable'" ghost type="primary">打印</a-button>
        </span>
      </template>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
        <i class='anticon anticon-info-circle ant-alert-icon'></i> 已选择 <a
        style='font-weight: 600'>{{ selectedRowKeys.length }}</a>项
        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>
      </div>

      <a-table
        id="datatable"
        ref='table'
        size='middle'
        :scroll='{x:true}'
        :expandedRowKeys='expandedRowKeys'
        @expand='fatherExpand'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        class='j-table-force-nowrap'
        @change='handleTableChange'>
        <!-- 教学计划模板编辑、删除按钮 -->
        <span slot='action' slot-scope='text, record'>
          <a @click='handleEdit(record)'><a-icon type='edit' /></a>
          <a-popconfirm title='确定删除吗?' @confirm='() => handleCoursePlanDelete(record.id)'>
            <a style='margin-left: 10px;'><a-icon type='delete' /></a>
          </a-popconfirm>
          <!--          <a @click="handleDetail(record)">详情</a>-->
          <!--          <a-divider type="vertical" />-->
          <!--          <a-dropdown>-->
          <!--            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>-->
          <!--            <a-menu slot="overlay">-->
          <!--              <a-menu-item>-->
          <!--                <a @click="handleDetail(record)">详情</a>-->
          <!--              </a-menu-item>-->
          <!--              <a-menu-item>-->
          <!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
          <!--                  <a>删除</a>-->
          <!--                </a-popconfirm>-->
          <!--              </a-menu-item>-->
          <!--            </a-menu>-->
          <!--          </a-dropdown>-->
        </span>
        <!-- 嵌入子table -->
        <a slot='operation' slot-scope='text'>Publish</a>
        <a-table
          slot='expandedRowRender'
          style='background-color: #eaeaea'
          slot-scope='record'
          :columns='innerColumns'
          :data-source='innerData'
          :pagination='false'
          class='components-table-demo-nested'
          bordered>
          <span slot='action' slot-scope='text, record'>
            <a @click='editChildCoursePlan(record)'>编辑</a>
            <a style='margin-left: 20px;' @click='addChildCoursePlan()'>新增</a>
            <a style='margin-left: 20px;' @click='deleteChildCoursePlan(record)'>删除</a>
          </span>
        </a-table>
      </a-table>
    </div>
    <cou-course-plan-modal ref='modalForm' @ok='modalFormOk'></cou-course-plan-modal>
    <!-- 教学计划详情model -->
    <div>
      <a-modal title='新增或编辑教学计划元素' :visible='visible' @ok='handleOk' @cancel='handleCancel'>
        <a-row>
          <a-col :span='24'>
            <a-form-model-item label='所属教学计划模板' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='coursePlanId'>
              <a-select v-model='editPlanAtomModel.coursePlanId' placeholder='请选择教学计划模板'
                        :getPopupContainer='(target) => target.parentNode' style='width: 100%'>
                <a-select-option v-for='item in coursePlanList' :key='item.value'>{{ item.label }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <a-form-model-item label='科目元素' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='subjectId'>
              <a-select v-model='editPlanAtomModel.subjectId' placeholder='请选择教学科目元素'
                        :getPopupContainer='(target) => target.parentNode' style='width: 50%'>
                <a-select-option v-for='item in subjectList' :key='item.value'>{{ item.label }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <a-form-model-item label='单双周标识' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='courPlanAtomIzSingle'>
              <a-input-number v-model='editPlanAtomModel.courPlanAtomIzSingle' placeholder='请输入单双周标识'
                              style='width: 100%' />
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <a-form-model-item label='周课时' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='courPlanAtomWeekHours'>
              <a-input-number v-model='editPlanAtomModel.courPlanAtomWeekHours' placeholder='请输入周课时'
                              style='width: 100%' />
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <a-form-model-item label='学期课时' :labelCol='labelCol' :wrapperCol='wrapperCol'
                               prop='courPlanAtomSemestarHours'>
              <a-input-number v-model='editPlanAtomModel.courPlanAtomSemestarHours' placeholder='请输入学期课时'
                              style='width: 100%' />
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <a-form-model-item label='开始周次' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='courPlanAtomStartWeek'>
              <a-input-number v-model='editPlanAtomModel.courPlanAtomStartWeek' placeholder='请输入开始周次'
                              style='width: 100%' />
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <a-form-model-item label='结束周次' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='courPlanAtomEndWeek'>
              <a-input-number v-model='editPlanAtomModel.courPlanAtomEndWeek' placeholder='请输入结束周次'
                              style='width: 100%' />
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <a-form-model-item label='开始日期' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='courPlanAtomStartDate'>
              <j-date placeholder='请选择开始日期' v-model='editPlanAtomModel.courPlanAtomStartDate' style='width: 100%' />
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <a-form-model-item label='结束日期' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='courPlanAtomEndDate'>
              <j-date placeholder='请选择结束日期' v-model='editPlanAtomModel.courPlanAtomEndDate' style='width: 100%' />
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <a-form-model-item label='状态' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='courPlanAtomStatus'>
              <j-dict-select-tag type='list' v-model='editPlanAtomModel.courPlanAtomStatus' style='width: 50%'
                                 dictCode='	cour_plan_atom_status'
                                 placeholder='请选择状态' />
            </a-form-model-item>
          </a-col>

        </a-row>
      </a-modal>
    </div>
    <!-- 教学计划下达 -->
    <div>
      <a-modal title='教学计划下达' :visible='coursePlanAppVisible' @ok='handleCoursePlanAppOk'
               @cancel='handleCoursePlanAppCancel'>
        <a-row>
          <a-col :span='24'>
            <a-form-model-item label='下达计划名称' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='coursePlanId'>
              <!--              <a-input v-model="corsePlanAppModel.coursePlanId" placeholder="请输入计划id"  ></a-input>-->
              <a-select v-model='corsePlanAppModel.coursePlanId' placeholder='请选择要下达的计划'
                        :getPopupContainer='(target) => target.parentNode' style='width: 100%'>
                <a-select-option v-for='item in coursePlanList' :key='item.value'>{{ item.label }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <a-form-model-item label='关联对象类型' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='relObjTtype'>
              <j-dict-select-tag @change='handleChanegObjType' type='list' v-model='corsePlanAppModel.relObjTtype'
                                 dictCode='course_target_obj_ttype' style='width: 100%' placeholder='请选择关联对象类型' />
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <a-form-model-item label='目标对象' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='relObjId'>
              <a-select v-model='corsePlanAppModel.relObjId' placeholder='请输入目标对象'
                        :getPopupContainer='(target) => target.parentNode' style='width: 100%'>
                <a-select-option v-for='item in objectList' :key='item.value'>{{ item.label }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="关联对象类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="relObjTtype">-->
          <!--              <a-input-number v-model="corsePlanAppModel.relObjTtype" style="width: 100%" placeholder="请输入关联对象类型" style="width: 100%" />-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <a-col :span='24'>
            <a-form-model-item label='计划执行状态' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='courPlanExecStatus'>
              <!--              <a-input-number v-model="corsePlanAppModel.courPlanExecStatus" style="width: 100%" placeholder="请输入计划执行状态"/>-->
              <j-dict-select-tag type='list' v-model='corsePlanAppModel.courPlanExecStatus'
                                 dictCode='cour_plan_exec_status' style='width: 100%' placeholder='请选择关联对象类型' />
            </a-form-model-item>
          </a-col>
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="是否有效" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="izOpen">-->
          <!--              <a-input-number v-model="corsePlanAppModel.izOpen" style="width: 100%" placeholder="请输入是否有效" style="width: 100%" />-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <a-col :span='24'>
            <a-form-model-item label='创建(下达)时间' :labelCol='labelCol' style='width: 100%' :wrapperCol='wrapperCol'
                               prop='createTime'>
              <j-date placeholder='请选择(下达)创建时间' v-model='corsePlanAppModel.createTime' style='width: 100%' />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-modal>
    </div>
    <!-- 查看教学计划下达记录 -->
    <div>
      <a-modal title='教学计划下达记录' :visible='coursePlanAppDetailsVisible' @cancel='handleCoursePlanAppDetailsCancel'
               width='80%'>
        <a-row>
          <a-table
            ref='table'
            size='middle'
            :scroll='{x:true}'
            bordered
            rowKey='id'
            :columns='course_plan_app_columns'
            :dataSource='coursePlanAppData'
            :pagination='ipagination'
            :loading='loading'
            :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
            class='j-table-force-nowrap'
            @change='handleTableChange'>

          </a-table>
        </a-row>
      </a-modal>
    </div>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import CouCoursePlanModal from './modules/CouCoursePlanModal'
import { deleteAction, getAction, postAction, putAction } from '@api/manage'
import {
  getSubjectList,
  getClassroomDataList,
  getAllClass,
  getClassStudentQueryAll,
  getTeacherList
} from '@api/commonAPI'
import { YEAR_SEMESTER } from '@/store/mutation-types'

export default {
  name: 'CouCoursePlanList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    CouCoursePlanModal
  },
  data() {
    return {
      description: 'cou_course_plan管理页面',
      // 表头
      columns: [
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 50,
          scopedSlots: { customRender: 'action' }
        },
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '计划编码',
          align: 'center',
          dataIndex: 'coursePlanCode'
        },
        {
          title: '计划名称',
          align: 'center',
          dataIndex: 'coursePlanName'
        },
        {
          title: '学期名称',
          align: 'center',
          dataIndex: 'semesterId_dictText'
        },
        {
          title: '学年名称',
          align: 'center',
          dataIndex: 'schoolYearId_dictText'
        },
        {
          title: '年级名称',
          align: 'center',
          dataIndex: 'gradeId_dictText'
        },
        {
          title: '科目名称',
          align: 'center',
          dataIndex: 'subjectId_dictText'
        },
        {
          title: '计划生效日期',
          align: 'center',
          dataIndex: 'coursePlanStartDate',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '计划失效日期',
          align: 'center',
          dataIndex: 'coursePlanEndDate',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'coursePlanStatus_dictText'
        },
        {
          title: '是否启用',
          align: 'center',
          dataIndex: 'izOpen_dictText'
        },
        {
          title: '是否删除',
          align: 'center',
          dataIndex: 'izDelete_dictText'
        },
        {
          title: '创建时间',
          align: 'center',
          sorter: true,
          dataIndex: 'createTime',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '创建人',
          align: 'center',
          dataIndex: 'createTeacherName'
        },
        {
          title: '编辑时间',
          align: 'center',
          dataIndex: 'editTime',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '编辑人',
          align: 'center',
          dataIndex: 'editTeacherName'
        }
      ],
      visible: false,
      innerColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 50,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        // {
        //   title:'计划id',
        //   align:"center",
        //   dataIndex: 'coursePlanId'
        // },
        // {
        //   title:'计划id',
        //   align:"center",
        //   dataIndex: 'coursePlanName'
        // },
        // {
        //   title:'科目编码',
        //   align:"center",
        //   dataIndex: 'subjectId'
        // },
        {
          title: '科目编码',
          width: 100,
          align: 'center',
          dataIndex: 'subjectName'
        },
        {
          title: '单双周标识',
          width: 70,
          align: 'center',
          dataIndex: 'courPlanAtomIzSingle'
        },
        {
          title: '周课时',
          width: 60,
          align: 'center',
          dataIndex: 'courPlanAtomWeekHours'
        },
        {
          title: '学期课时',
          width: 60,
          align: 'center',
          dataIndex: 'courPlanAtomSemestarHours'
        },
        {
          title: '开始周次',
          width: 60,
          align: 'center',
          dataIndex: 'courPlanAtomStartWeek'
        },
        {
          title: '结束周次',
          width: 60,
          align: 'center',
          dataIndex: 'courPlanAtomEndWeek'
        },
        {
          title: '开始日期',
          width: 100,
          align: 'center',
          dataIndex: 'courPlanAtomStartDate',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '结束日期',
          width: 100,
          align: 'center',
          dataIndex: 'courPlanAtomEndDate',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '状态',
          width: 80,
          align: 'center',
          dataIndex: 'courPlanAtomStatus_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 120,
          scopedSlots: { customRender: 'action' }
        }
      ],
      expandedRowKeys: [],
      innerData: [],
      dataSource: [],
      serchParams: {
        schoolYearId: this.$ls.get(YEAR_SEMESTER).schoolYearId,
        semesterId: this.$ls.get(YEAR_SEMESTER).semesterId
      },
      course_plan_app_columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        // {
        //   title:'计划id',
        //   align:"center",
        //   dataIndex: 'coursePlanId'
        // },
        {
          title: '计划名称',
          align: 'center',
          dataIndex: 'coursePlanAppName'
        },
        // {
        //   title:'目标对象',
        //   align:"center",
        //   dataIndex: 'relObjId'
        // },
        {
          title: '目标对象名称',
          align: 'center',
          dataIndex: 'objectName'
        },
        {
          title: '关联对象类型',
          align: 'center',
          dataIndex: 'relObjTtype_dictText'
        },
        // {
        //   title:'关联对象类型英文名称',
        //   align:"center",
        //   dataIndex: 'relObjNameEn_dictText'
        // },
        // {
        //   title:'关联对象类型中文名称',
        //   align:"center",
        //   dataIndex: 'relObjNameCn_dictText'
        // },
        {
          title: '计划执行状态',
          align: 'center',
          dataIndex: 'courPlanExecStatus_dictText'
        },
        {
          title: '是否有效',
          align: 'center',
          dataIndex: 'izOpen_dictText'
        },
        {
          title: '是否删除',
          align: 'center',
          dataIndex: 'izDelete_dictText'
        },
        {
          title: '创建人',
          align: 'center',
          dataIndex: 'createUserId'
        },
        {
          title: '创建时间',
          align: 'center',
          sorter: true,
          dataIndex: 'createTime',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        //计划模板相关
        list: '/courseplan/couCoursePlan/list',
        delete: '/courseplan/couCoursePlan/delete',
        deleteBatch: '/courseplan/couCoursePlan/deleteBatch',
        exportXlsUrl: '/courseplan/couCoursePlan/exportXls',
        importExcelUrl: 'courseplan/couCoursePlan/importExcel',
        planIzdelete: '/courseplan/couCoursePlan/planIzdelete',
        //计划详情元素相关
        atomList: '/courseplanatom/couCoursePlanAtom/coursePlanByCoursePlanId',
        atom_add: '/courseplanatom/couCoursePlanAtom/planAtomAdd',
        atom_edit: '/courseplanatom/couCoursePlanAtom/planAtomEdit',
        atom_queryById: '/courseplanatom/couCoursePlanAtom/queryById',
        atom_delete: '/courseplanatom/couCoursePlanAtom/delete',
        atom_deleteBatch: '/courseplanatom/couCoursePlanAtom/deleteBatch',
        atom_exportXlsUrl: '/courseplanatom/couCoursePlanAtom/exportXls',
        atom_mportExcelUrl: 'courseplanatom/couCoursePlanAtom/importExcel',
        //科目数据
        atom_listAllSubject: '/subject/couSubject/list',
        //计划下达相关
        course_plan_app_list: '/relcourseplanapp/relCoursePlanApp/list',
        course_plan_app_add: '/relcourseplanapp/relCoursePlanApp/add'
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      dictOptions: {},
      superFieldList: [],
      coursePlanList: [],
      subjectList: [],
      //计划详情元素model
      editPlanAtomModel: {
        id: null,
        coursePlanId: null,
        coursePlanName: null,
        subjectId: null,
        subjectName: null,
        courPlanAtomIzSingle: null,
        courPlanAtomWeekHours: null,
        courPlanAtomSemestarHours: null,
        courPlanAtomStartWeek: null,
        courPlanAtomEndWeek: null,
        courPlanAtomStartDate: null,
        courPlanAtomEndDate: null,
        courPlanAtomStatus: null,
        izOpen: null,
        izDelete: null,
        tenantId: null,
        createTime: null,
        createUserId: null,
        editTime: null,
        editUserId: null
      },
      coursePlanAppVisible: false,
      //计划下达model
      corsePlanAppModel: {
        id: null,
        coursePlanId: null,
        relObjId: null,
        relObjTtype: null,
        relObjNameEn: null,
        relObjNameCn: null,
        courPlanExecStatus: null,
        izOpen: null,
        izDelete: null,
        createUserId: null,
        createTime: null,
        tenantId: null,
        coursePlanAppName: null,
        objectName: null
      },
      objectList: [],
      //查看教学计划下达记录
      coursePlanAppDetailsVisible: false,
      coursePlanAppData: []
    }
  },
  created() {
    Object.assign(this.queryParam, this.serchParams)
    this.getSuperFieldList()
    this.getCoursePlanData()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  mounted() {

  },
  methods: {
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'coursePlanCode', text: '计划编码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'coursePlanName', text: '计划名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'semesterId', text: '学期ID', dictCode: '' })
      fieldList.push({ type: 'string', value: 'schoolYearId', text: '学年ID', dictCode: '' })
      fieldList.push({ type: 'string', value: 'gradeId', text: '年级ID', dictCode: '' })
      fieldList.push({ type: 'string', value: 'subjectId', text: '科目编码', dictCode: '' })
      fieldList.push({ type: 'date', value: 'coursePlanStartDate', text: '计划生效日期' })
      fieldList.push({ type: 'date', value: 'coursePlanEndDate', text: '计划失效日期' })
      fieldList.push({ type: 'int', value: 'coursePlanStatus', text: '状态（1：编制 2：发布 3：应用 4：过期 5：下线）', dictCode: '' })
      fieldList.push({ type: 'int', value: 'izOpen', text: '是否启用（1是（启用） 0否 （未启用））', dictCode: '' })
      fieldList.push({ type: 'int', value: 'izDelete', text: '是否删除（1是 0：否）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenantId', text: '学校编码(租户)', dictCode: '' })
      fieldList.push({ type: 'date', value: 'createTime', text: '创建时间' })
      fieldList.push({ type: 'string', value: 'createUserId', text: '创建人（ID）', dictCode: '' })
      fieldList.push({ type: 'date', value: 'editTime', text: '编辑时间' })
      fieldList.push({ type: 'string', value: 'editUserId', text: '编辑人id', dictCode: '' })
      this.superFieldList = fieldList
    },
    fatherExpand(expanded, record) {
      if (expanded) {
        this.expandedRowKeys.push(record.id)
        this.getChildTable(record)
      } else {
        this.expandedRowKeys.splice(this.expandedRowKeys.indexOf(record.id), 1)
      }
    },

    //条件查询
    whereSerchCoursePlan() {
      this.getCoursePlanData()
    },
    //重置查询条件
    whereSerchCoursePlanInit() {
      this.serchParams = []
      this.getCoursePlanData()
    },
    getCoursePlanData() {
      let couCoursePlan = {
        subjectId: this.serchParams.subjectId,
        schoolYearId: this.serchParams.schoolYearId,
        semesterId: this.serchParams.semesterId,
        gradeId: this.serchParams.gradeId,
        coursePlanStatus: this.serchParams.coursePlanStatus,
        izOpen: this.serchParams.izOpen
      }
      getAction(this.url.list, couCoursePlan).then((res) => {
        if (res.success && res && res.code === 200) {
          this.dataSource = res.result.records
          console.log(this.dataSource)
        }
      })
    },
    addChildCoursePlan() {
      this.visible = true
      //获取新增、编辑下拉计划模板数据
      getAction(this.url.list).then(res => {
        if (res.success) {
          this.coursePlanList = []
          res.result.records.forEach(item => {
            this.coursePlanList.push({
              label: item.coursePlanName,
              value: item.id
            })
          })
        } else {
          this.$message.error(res.message)
        }
      })
      //获取新增、编辑下拉科目数据
      getAction(this.url.atom_listAllSubject).then(res => {
        if (res.success) {
          this.subjectList = []
          res.result.records.forEach(item => {
            this.subjectList.push({
              label: item.subjectName,
              value: item.id
            })
          })
        } else {
          this.$message.error(res.message)
        }
      })
    },
    editChildCoursePlan(record) {
      this.visible = true
      this.editPlanAtomModel = record
      let params = {
        courseAtomId: record.id
      }
      //获取新增、编辑下拉计划模板数据
      getAction(this.url.list).then(res => {
        if (res.success) {
          this.coursePlanList = []
          res.result.records.forEach(item => {
            this.coursePlanList.push({
              label: item.coursePlanName,
              value: item.id
            })
          })
        } else {
          this.$message.error(res.message)
        }
      })
      //获取新增、编辑下拉科目数据
      getAction(this.url.atom_listAllSubject).then(res => {
        if (res.success) {
          this.subjectList = []
          res.result.records.forEach(item => {
            this.subjectList.push({
              label: item.subjectName,
              value: item.id
            })
          })
        } else {
          this.$message.error(res.message)
        }
      })
    },
    handleCoursePlanDelete(record) {
      //教学计划模板删除 只是逻辑删除（iz_delete）
      let params = {
        id: record
      }
      putAction(this.url.planIzdelete, params).then(res => {
        if (res.success) {
          this.$message.success('删除成功')
        } else {
          this.$message.error('删除失败')
        }
      })
    },
    deleteChildCoursePlan(record) {
      let params = {
        id: record.id
      }
      //获取删除计划详情元素
      deleteAction(this.url.atom_delete, params).then(res => {
        if (res.success) {
          this.visible = false
          this.$message.success('删除成功')
        } else {
          this.$message.error('删除失败')
        }
      })

    },
    handleCancel() {
      this.visible = false
      //提交后需要清空数据 否则影响新增操作
      this.editPlanAtomModel = []
    },
    handleOk() {
      if (this.editPlanAtomModel.id == null || this.editPlanAtomModel == '') {
        //如果id不存在 则执新增
        putAction(this.url.atom_add, this.editPlanAtomModel).then(res => {
          if (res.success) {
            this.visible = false
            this.$message.success('新增成功')
          } else {
            this.$message.error('新增失败')
          }
        })
      } else {
        putAction(this.url.atom_edit, this.editPlanAtomModel).then(res => {
          if (res.success) {
            this.visible = false
            this.$message.success('编辑成功')
          } else {
            this.$message.error('编辑失败')
          }
        })
      }
      //提交后需要清空数据 否则影响新增操作
      this.editPlanAtomModel = []
    },
    getChildTable(record) {
      let params = {
        coursePlanId: record.id
      }
      getAction(this.url.atomList, params).then(res => {
        if (res.success) {
          this.innerData = res.result
        } else {
          this.$message.error(res.message)
        }
      })
    },
    coursePlanApp() {
      this.coursePlanAppVisible = true
      //获取新增、编辑下拉计划模板数据
      getAction(this.url.list).then(res => {
        if (res.success) {
          this.coursePlanList = []
          res.result.records.forEach(item => {
            this.coursePlanList.push({
              label: item.coursePlanName,
              value: item.id
            })
          })
        } else {
          this.$message.error(res.message)
        }
      })
    },
    handleCoursePlanAppCancel() {
      this.coursePlanAppVisible = false
    },
    handleChanegObjType() {
      let type = this.corsePlanAppModel.relObjTtype
      this.objectList = []
      // this.corsePlanAppModel.relObjTtype = ''
      switch (type) {
        case '1':
          this.getClassesList()
          break
        case '2' :
          this.getClassroomList()
          break
        case '3':
          this.getTeacherList()
          break
        case '4':
          this.getSubjectList()
          break
        case '5':
          this.getStudentList()
          break
        default :
          this.$message.error('获取初始化数组出错')
      }
    },
    async getClassesList() {
      let res = await getAllClass()
      if (res.success) {
        res.result.forEach(item => {
          this.objectList.push({
            label: item.className,
            value: item.id
          })
        })
      } else {
        this.$message.error('获取初始化数组出错')
      }
    },
    async getClassroomList() {
      let res = await getClassroomDataList()
      if (res.success) {
        res.result.forEach(item => {
          this.objectList.push({
            label: item.classroomName,
            value: item.id
          })
        })
      } else {
        this.$message.error('获取初始化数组出错')
      }
    },
    async getTeacherList() {
      let res = await getTeacherList()
      if (res.success) {
        res.result.forEach(item => {
          this.objectList.push({
            label: item.teacherName,
            value: item.teacherId
          })
        })
      } else {
        this.$message.error('获取初始化数组出错')
      }
    },
    async getSubjectList() {
      let res = await getSubjectList()
      if (res.success) {
        res.result.forEach(item => {
          this.objectList.push({
            label: item.subjectName,
            value: item.subjectId
          })
        })
      } else {
        this.$message.error('获取初始化数组出错')
      }
    },
    async getStudentList() {
      let res = await getClassStudentQueryAll()
      if (res.success) {
        res.result.forEach(item => {
          this.objectList.push({
            label: item.studentName,
            value: item.id
          })
        })
      } else {
        this.$message.error('获取初始化数组出错')
      }
    },
    //教学计划下达 新增或编辑提交方法
    handleCoursePlanAppOk() {
      postAction(this.url.course_plan_app_add, this.corsePlanAppModel).then(res => {
        if (res.success) {
          this.$message.success('下达成功')
        } else {
          this.$message.error('下达失败')
        }
      })
      this.coursePlanAppVisible = false
    },
    //查看教学计划下达记录
    viewCoursePlanAppDetails() {
      this.coursePlanAppDetailsVisible = true
      getAction(this.url.course_plan_app_list).then(res => {
        if (res.success) {
          this.coursePlanAppData = []
          this.coursePlanAppData = res.result.records
        } else {
          this.$message.error(res.message)
        }
      })
    },
    handleCoursePlanAppDetailsCancel() {
      this.coursePlanAppDetailsVisible = false
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>